﻿
Partial Class Paginas_PublicarEvento
    Inherits System.Web.UI.Page

#Region "Declaracion de Funciones y Procedimientos de pagina"
    Private Sub CargarInfoEvento()
        Dim objNegEven As New dllNegocio.NegEventos(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection
        Dim objEven As New dllEntidades.clsEventos
        Try
            myCollect = objNegEven.ListarEventos(Me.hdnIdEvento.Value.Trim, "", "0")
            If myCollect.Count > 0 Then
                objEven = myCollect.Item(1)
                Me.lblEvento.Text = objEven.Nombre
                Me.lblFecHoraIni.Text = objEven.FechaHoraInicioPublicacion.ToString
                Me.lblFecHoraFin.Text = objEven.FechaHoraFinPublicacion.ToString
                Me.lblLugar.Text = objEven.Lugar
                Me.hdnImagen.Value = objEven.ImagenMailEvento
            End If
            Call CargarGrillaFiltroEventos()
        Catch ex As Exception
        Finally
            objNegEven.Dispose()
            objNegEven = Nothing
            myCollect = Nothing
            objEven.Dispose()
            objEven = Nothing
        End Try
    End Sub

    Private Sub CargarGrillaFiltroEventos()
        Dim objNegConvLug As New dllNegocio.NegFiltrosEventos(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection
        Dim objEvento As New dllEntidades.clsEventos
        Try
            objEvento.Codigo = Me.hdnIdEvento.Value.Trim
            myCollect = objNegConvLug.ListarFiltroEventos(objEvento)
            Me.GrillaResultados.DataSource = myCollect
            Me.GrillaResultados.DataBind()
        Catch ex As Exception
        Finally
            myCollect = Nothing
            objNegConvLug.Dispose()
            objNegConvLug = Nothing
        End Try
    End Sub

    Private Sub PublicarEvento()
        Dim objNegEventos As New dllNegocio.NegEventos(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim objEventos As New dllEntidades.clsEventos
        Dim objServidor As New dllNegocio.NegMail()
        Try
            objEventos.Codigo = Me.hdnIdEvento.Value.Trim
            Dim Ruta As String = Server.MapPath("~")
            Ruta = Ruta & IIf(Right(Ruta.ToString.Trim, 1) = "\", "", "\") & "Paginas\Img\ImgLoad\Eventos\" & Me.hdnImagen.Value.Trim
            objServidor.CorreoDesde = System.Configuration.ConfigurationManager.AppSettings.Get("CorreoDesde")
            objServidor.ServidorMail = System.Configuration.ConfigurationManager.AppSettings.Get("ServidorMail")
            If objNegEventos.publicarEvento(objEventos, objServidor, Ruta) = True Then
                UtilidadesPagina.EjecutaScript("PublicacionCorrecta();", Me.Page)
            End If
        Catch ex As Exception
            UtilidadesPagina.EjecutaScript("alert('" & ex.Message.ToString.Replace(Chr(13), "/n") & "');", Me.Page)
        Finally
            objNegEventos.Dispose()
            objNegEventos = Nothing
            objEventos.Dispose()
            objEventos = Nothing
        End Try
    End Sub
#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.hdnIdEvento.Value = Request.QueryString("EventoID") '
            Call CargarInfoEvento()
        End If
    End Sub

    Protected Sub btnVolver_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVolver.Click
        Response.Redirect("ListarEventos.aspx?PostBack=SI")
        Response.End()
    End Sub

    Protected Sub btnPublicar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPublicar.Click
        Call PublicarEvento()
    End Sub

End Class
